﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MyLibrary.Tools
{
    /// <summary>
    /// 获取与磁盘相关的信息
    /// </summary>
    public class DiskInfo
    {
        private DiskInfo()
        {
        }

        [DllImport("kernel32.dll")]
        private static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out UInt64 lpFreeBytesAvailable, out UInt64 lpTotalNumberOfBytes, out UInt64 lpTotalNumberOfFreeBytes);

        /// <summary>
        /// 获取分区的空间信息 
        /// </summary>
        /// <param name="disk">分区号</param>
        /// <param name="freeSpace">可用空间(byte)</param>
        /// <param name="totalSpace">总空间数据(byte)</param>
        public static void GetDiskSpaceInfo(string disk, out ulong freeSpace, out ulong totalSpace)
        {
            if (String.IsNullOrEmpty(disk))
                throw new ArgumentNullException("盘符为空");
            ulong temp = 0;

            GetDiskFreeSpaceEx(disk, out freeSpace, out totalSpace, out temp);
        }
    }
}
